#include <iostream>

using namespace std;
 
typedef struct Node{
	int data;
	Node * left;
	Node * right;
} Node;

int f(Node* node, int t){
	int n;
	
	// left child
	if(node->left != NULL) n = f(node->left,t);
	if(n == 1) return 1;
	
	// right child
	if(node->right != NULL) n = f(node->right,t);
	if(n == 1) return 1;
	
	// root 
	cout<<"check " << node->data << "......" << endl;
	if(node->data == t) return 1;
	
	return 0;
} 

int f2(Node* node, int t){
	int n;
	
	// root 
	cout<<"check " << node->data << "......" << endl;
	if(node->data == t) return 1;
	
	// left child
	if(node->left != NULL) n = f2(node->left,t);
	if(n == 1) return 1;
	
	// right child
	if(node->right != NULL) n = f2(node->right,t);
	if(n == 1) return 1;
	
	return 0;
} 

Node* createNode(int d){
	Node* temp = new Node();
	temp->data = d;
	return temp;
}

int main(){
  Node* root = createNode(50);
  root->left = createNode(25);
  root->right = createNode(75);
  
  root->left->left = createNode(12);
  root->left->right = createNode(37);  
  root->right->left = createNode(62);
  root->right->right = createNode(88);
  
  cout<<"=======================finding 60======================="<<endl;
  if(f2(root, 60)==1) cout<<"found!";
  else cout<<"NOT found!"<<endl<<endl;
  
  cout<<"=======================finding 37======================="<<endl;
  if(f2(root, 37)==1) cout<<"found!";
  else cout<<"NOT found!";
  
  
}
